<?php
require_once 'includes/include_dao.php';
$template = $_GET['template'];
$template = $_GET['tag'];
$template = $_GET['label'];

if (!empty($_GET['tag'])) :
	$tag = DAOFactory::getTagDAO()->

load($_GET['tag']);
	$template = $tag->template;
endif;
if (!empty($_GET['label'])) :
	$tag = DAOFactory::getTagDAO()->queryByLabel($_GET['label']);
	// current request fetches list instead of row
	$template = $tag[0]->template;
endif;
if (!empty($_GET['template'])) :
	$tag = DAOFactory::getTagDAO()->queryByTemplate($_GET['template']);
	// current request fetches list instead of row
	$template = $tag[0]->template;
endif;

$template = DAOFactory::getTemplateDAO()->load($template); 

if ($template) :
	header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); 
	header('Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT'); 
	header('Cache-Control: no-store, no-cache, must-revalidate'); 
	header('Cache-Control: post-check=0, pre-check=0', false); 
	header('Pragma: no-cache'); 
	header('Content-Type: text/plain'); // plain text file
	// Headers for an download:
	header('Content-Type: application/octet-stream');
	header('Content-Disposition: attachment; filename="ks.cfg"'); 
	header('Content-Transfer-Encoding: binary');
	echo '# Title: ' . $template->title . "\r\n";
	echo '# Generated using sparked http://code.google.com/p/sparked/' . "\r\n";
	echo '# Downloaded: ' . date('Y-m-d H:i:s') . ' ' . $_SERVER['HTTP_REFERER'] . "\r\n";
	echo '# Updated: ' . $template->updated . "\r\n";
	echo "\r\n";
	echo $template->document;
else :
	echo 'Error - no kickstart';
endif;